<?php
// +----------------------------------------------------------------------
// | Scallion 
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.scallion.top All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Liuxg < 420695648@qq.com>
// +----------------------------------------------------------------------

use mikkle\tp_wechat\Wechat;
use think\Db;
use think\queue\Job;
/**
 * 微信信息同送接口操作类
 * 推荐继承或者复制本类进行修改即可
 * Power: Mikkle
 * Email：776329498@qq.com
 * Class WechatApi
 * @package mikkle\tp_wechat
 */
class WechatController extends Wechat
{
	public function __construct(array $options = [])
    {
		$data = Db::name('option')->where(['option_name'=>'wechat_option'])->find();
		$this->options = json_decode($data['option_value'],true);
	}
	
    function wx_get_qrcode($scene_id,$type,$expire){
		
		$qrcode = $this->extend($this->options);
		$ticket = $qrcode->getQRCode($scene_id,$type,$expire);
		if($ticket){
			$qrcode_img = $qrcode->getQRUrl($ticket['ticket']);
			return $qrcode_img;
		}
		else{
			return false;
		}
	}
	
	function wx_get_fans($openid){
		$fans = $this->user($this->options);
		$user_info = $fans->getUserInfo($openid);
		if($user_info){
			return $user_info;
		}
		else{
			return false;
		}
	}
	
	function wx_send_template_message($data){
		$msg = $this->message($this->options);
		$res = $msg->sendTemplateMessage($data);
		return $res;
	}
	
	function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base'){
		$obj = $this->oauth($this->options);
		$res = $obj->getOauthRedirect($callback,$state,$scope);
		return $res;
	}
	
	function getOauthAccessToken(){
		$obj = $this->oauth($this->options);
		return $obj->getOauthAccessToken();
	}
}